<?php
/**
 * Gerenciamento de idiomas
 * Author: Bruno Ramos <contato [AT] brunoramos [DOT] eti [DOT] br>
 * File: idioma.php
 * Version: 1.0
 */
    //verifica idioma atual
    if(isset($_COOKIE["lang"]))
        $lang = $_COOKIE["lang"];
    if(isset($_SESSION["lang"]))
        $lang = $_SESSION["lang"];
    else
        $lang = $config["lang"];
        
    if(isset($_COOKIE["langId"]))
        $langId = $_COOKIE["langId"];
    if(isset($_SESSION["langId"]))
        $langId = $_SESSION["langId"];
    else 
        $langId = $config["langId"];
   
    
    $_SESSION["lang"] = $lang;
    $_SESSION["langId"] = $langId;
    $newLang = $lang;
    if ($url[0] == "lang") {
        PDO4You::getInstance();    
        $result = PDO4You::select("SELECT id FROM idioma WHERE ativo='TRUE' AND idioma='".strtoupper($url[1])."'");
        if(PDO4You::rowCount() > 0) {
            $newLang = strtoupper($url[1]);
            setcookie("lang", $newLang,time() + 31536000, "/");
            setcookie("langId", $result[0]["id"],time() + 31536000, "/");
            $_SESSION["lang"] = $newLang;
            $_SESSION["langId"] = $langId = $result[0]["id"];
        }
    }
    
    require_once("lang/".strtolower($newLang).".php");
    $smarty->assign("lang", $lang_database);
    
    if($url[0] == "lang")
        echo "<script type='text/javascript'>window.location = '".$baseUrl."';</script>";
		//header("Location: ".$baseUrl);
?>
